package com.qpf

def closure1 = {println "hello groovy"}
def closure2 = {name, age -> println "hello ${name}, ${age}"}

closure1.call()

closure2.call("121", 12)


def closure = {println "hello ${it}"}
closure('groovy')


def result = 1
1.upto(5, {num -> result *= num})
println result

result = 1
5.downto(1) {num -> result *= num}
println result

result = 0
5.times {num -> result += num}
println result


def str = "2 add 5 is 7"

println str.find {num -> num.isNumber()}
println str.findAll {num -> num.isNumber()}
str.each {c -> print(c)} println()
println str.any {it.isNumber()}
println str.every {it.isNumber()}
println str.collect {it.toUpperCase()}




class Student {
    def name

    def property = {
        "Hello ${name}"
    }

    @Override
    java.lang.String toString() {
        return property.call()
    }
}
class Teacher {
    def name
}

def student = new Student(name: 'student')
def teacher = new Teacher(name: 'teacher')
println(student)
student.property.delegate = teacher
student.property.resolveStrategy = groovy.lang.Closure.DELEGATE_FIRST
println(student)